package cn.wgx.commons.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;


@Slf4j
@WebFilter(urlPatterns = "/api/fileupload/addAppend")
@Order(99) //测试好像这个参数不生效，实际生效的是Filter扫描到的顺序（所以起名很重要）
public class TimeFilter implements Filter {



    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        chain.doFilter(request,response);
//        if(request instanceof HttpServletRequest){
//            HttpServletRequest httpServletRequest = (HttpServletRequest)request;
//            String requestURI = (httpServletRequest).getRequestURI();
//            if(requestURI.contains("/api/fileupload/addAppend")){
//                long s = System.currentTimeMillis();
//                if(log.isDebugEnabled()){
//                    log.debug("filter开始: {}" , s);
//                }
//                chain.doFilter(request,response);
//                if(log.isDebugEnabled()){
//                    long s2 = System.currentTimeMillis();
//                    log.debug("上传总时间是: {}" , (s2 - s));
//                }
//            }
//        }

    }



}
